//#include "QueueManager.h"
//#include "NCManager.h"
//#include <fstream>
//#include <string>
//#include <iostream>
//#include <pthread.h>
//
// NCManager* QueueManager::spaceship;
// int QueueManager::maxQueueSize;
//
//using namespace std;
//
//QueueManager::QueueManager()
//{
//}
//
//QueueManager::~QueueManager()
//{
//}
//
//void QueueManager::setMotherShip(NCManager* daddy)
//{
//    QueueManager::spaceship = daddy;
//}
//
//void QueueManager::setMaxQueueSize(int size)
//{
//    QueueManager::maxQueueSize = size;
//}
//int QueueManager::getMaxQueueSize()
//{
//    //cout << "here I am" << endl;
//    return QueueManager::maxQueueSize;
//}
//void *QueueManager::run(void* threadid)
//{
//    /**
//     * This method is to be executed as thread to
//     * keep the fetching queue sync.
//     */
//    unsigned int amountFetched=0;
//    bool aux = false;
//    sleep(30);
//    while(true) {
////    cout << "teste: " << QueueManager::getMaxQueueSize() << endl;
//    pthread_mutex_lock(&QueueManager::spaceship->queueMutex);
////    int QueueSize = spaceship->getVisitQueue()->size();   
//    pthread_mutex_unlock(&QueueManager::spaceship->queueMutex);
////    cout << "tam: " << QueueSize << endl;
//    pthread_mutex_lock(&QueueManager::spaceship->queueMutex);
//    priority_queue <string, vector<string>, URLComparison>* fila = QueueManager::spaceship->getVisitQueue();
//    pthread_mutex_unlock(&QueueManager::spaceship->queueMutex);
//    aux = (QueueSize < (200));
//    if(aux)
//    {
//        /**
//         * Let's fetch some pages to visit from the disk
//         * file, otherwise probes will get idle and we
//         * don't want it at all...
//         */
//        ifstream file ("visitque.nc", ios_base::in);
//        bool isEof = false;
//        int fetchedPages =0;
//        //go to the desired line
//        string dummy;
//        for(int i=0;i<=amountFetched;i++)
//        {
//            getline(file, dummy );
//        }
//        while(!isEof && fetchedPages <=(QueueManager::maxQueueSize/2))
//        {
//            getline(file, dummy);
//            pthread_mutex_lock(&QueueManager::spaceship->queueMutex);
//            fila->push(dummy);
//            pthread_mutex_unlock(&QueueManager::spaceship->queueMutex);
//            fetchedPages++;
//            amountFetched++;       
//        }
//       
//    }
//    else if(QueueSize >= QueueManager::maxQueueSize)
//    {
//        /**
//         * Let's use the disk to keep half the sites in the visit
//         * queue freeing the RAM to be used otherwise
//         */
//        ofstream queueFile ("visitque.nc",ios_base::out | ios_base::ate | ios_base::app);
//        int last_pos = QueueSize - QueueManager::maxQueueSize;
//        cout << "Tamanho da Fila: " << QueueSize << endl;
//        for(int i=0; i<last_pos;i++)
//        {
//            pthread_mutex_lock(&QueueManager::spaceship->queueMutex);
//            queueFile << fila->top() << endl;
//            cout << "Poping: " << queueFile << endl;
//            fila->pop();
//            pthread_mutex_unlock(&QueueManager::spaceship->queueMutex);
//        }
//        queueFile.close();
//    }
//        sleep(30);
//        cout << "Joined Thread =)" << endl;
//    }
//} 